genVectorAdd
in genMath.lib
Vector Functions Function List by Category Alphabetical Function
int genVectorAdd(
float *VectorA, // pointer to array holding
vector A
float *VectorB, // pointer to array holding
vector B
int dimen,
// dimension of vectors A and B
float *VectorSum) // pointer to
store resultant vector
This function adds two vectors of dimension n:
Resultant(i) = a(i) + b(i)
The explicit routines VectorAdd2d and VectorAdd3d
are faster due to code
optimizations in the explicit algorithms..
The
return code is errno, defined in the C standard library (math.h). This is
an integer value
for math errors.
Sample Application:
/////////// splgnAdd.c for genVectorAdd Library Function /////////////
// //
// For this sample, 3-d vectors are used. Vectors are stored //
// in arrays a and b, and the sum is returned into //
// the array c. //
// //
//////////////////////////////////////////////////////////////////////
//////////////////////////// INCLUDES ////////////////////////////////
#include "stdio.h"
#include "genMath.h"
////////////////////////////// MAIN //////////////////////////////////
void main()
{
//local declarations
//integers
int i; // dimension counter
int retcode; // return code for call to genVectorAdd
//floats
float a[3]; // vector A
float b[3]; // vector B
float c[3]; // resultant vector, C
//character strings
char ch; //input string to exit
//intialize the A and B vectors
a[0] = (float)1.234;
a[1] = (float)-.678;
a[2] = (float)10.3;
b[0] = (float)4.559;
b[1] = (float)3.24;
b[2] = (float)0.3422;
//compute the vector sum
retcode = genVectorAdd(a,b,3,c);
//display the result
printf("%s", "Resultant Components: \n\n");
for(i=0;i<=2;++i){
printf("%s%d%s%f%s", "c[",i,"] = ", c[i],"\n");
}
printf("%s","\n");
//display closing message and wait for <enter> before exiting
printf("Press <Enter> to end");
scanf("%c", &ch);
} // End Main
/////////////////////////////// End splgnAdd.c ///////////////////////
The reader may compute the vector sum of A and B and compare to the output of the sample program.
Output from the test program splgenDP.c:
Resultant Components:
c[0] = 5.793000
c[1] = 2.562000
c[3] = 10.642200